/*
 * Filename:    AuditDispatchServiceImpl.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014-11-11
 */
package com.paic.mhis.hcpms.audit.biz.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.paic.mhis.common.base.dto.PaginationDTO;
import com.paic.mhis.common.base.intergration.dao.CommonDAO;
import com.paic.mhis.hcpms.audit.biz.service.AuditService;
import com.paic.mhis.hcpms.audit.dao.AuditDao;
import com.paic.mhis.hcpms.common.base.dto.PaginatedQueryDTO;
import com.paic.pafa.app.biz.service.BusinessServiceException;

@Component("auditServiceImpl")
public class AuditServiceImpl implements AuditService {
	@Autowired
	private AuditDao auditDao;

	@Autowired
	private CommonDAO commonDAO;

	@Override
	public Map<String, Object> findProblemPage(int pageSize, int page,
			Map<String, Object> params, Map<String, Object> map)
			throws BusinessServiceException {
		PaginatedQueryDTO dto = new PaginatedQueryDTO();
		dto.setStart(pageSize);
		dto.setLimit(page);
		dto.setParam(params);
		map = auditDao.queryTaskPage(dto);
		return map;
	}

	@Override
	public Map<String, Object> findProblemAuditPage(int page, int pageSize,
			Map<Object, Object> params) throws BusinessServiceException {
		PaginationDTO dto = new PaginationDTO();
		if (pageSize <= 0) {
			pageSize = 20;
		}
		int start = 0, end = 0;
		if (page > 1) {
			start = (page - 1) * pageSize;
			end = page * pageSize;
		} else {
			start = 0;
			end = pageSize;
		}
		dto.setStart(start);
		dto.setEnd(end);
		dto.setDoCount(true);
		dto.setQueryAll(false);
		dto.setQueryParams(params);
		return commonDAO.queryPage("auditDao.findProblemAuditTaskList", dto);
		// PaginatedQueryDTO dto = new PaginatedQueryDTO();
		// dto.setStart(pageSize);
		// dto.setLimit(page);
		// dto.setParam(params);
		// return auditDao.queryTaskAuditPage(dto);

	}

	@Override
	public Map<String, Object> findProblemPageByStatus(int pageSize, int page,
			Map<String, Object> params) throws BusinessServiceException {
		PaginatedQueryDTO dto = new PaginatedQueryDTO();
		dto.setStart(pageSize);
		dto.setLimit(page);
		dto.setParam(params);
		return auditDao.queryProblemByStatus(dto);
	}

	@Override
	public Map<String, Object> findCasePage(int pageSize, int page,
			Map<String, Object> params, Map<String, Object> map)
			throws BusinessServiceException {
		PaginatedQueryDTO dto = new PaginatedQueryDTO();
		dto.setStart(pageSize);
		dto.setLimit(page);
		dto.setParam(params);
		map = auditDao.queryCaseTaskPage(dto);
		return map;
	}

	@Override
	public Map<String, Object> findCaseAuditPage(int pageSize, int page,
			Map<String, Object> params) throws BusinessServiceException {
		PaginatedQueryDTO dto = new PaginatedQueryDTO();
		dto.setStart(pageSize);
		dto.setLimit(page);
		dto.setParam(params);
		return auditDao.queryCaseAuditTaskPage(dto);
	}

	@Override
	public void saveProblemTemp(String problemCode) throws Exception {
		auditDao.saveProblemTemp(problemCode);
	}
}
